home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / libpng / pngset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-13  |  9.1 KB  |  313 lines

  1.  
  2. /* pngset.c - storage of image information into info struct
  3.  
  4.    libpng 1.0 beta 6 - version 0.96
  5.    For conditions of distribution and use, see copyright notice in png.h
  6.    Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  7.    Copyright (c) 1996, 1997 Andreas Dilger
  8.    May 12, 1997
  9.    */
  10.  
  11. #define PNG_INTERNAL
  12. #include "png.h"
  13.  
  14. #if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
  15. void
  16. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  17. {
  18.    png_debug1(1, "in %s storage function\n", "bKGD");
  19.    if (info_ptr == NULL)
  20.       return;
  21.  
  22.    png_memcpy(&(info_ptr->background), background, sizeof(png_color_16));
  23.    info_ptr->valid |= PNG_INFO_bKGD;
  24. }
  25. #endif
  26.  
  27. #if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
  28. void
  29. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  30.    double white_x, double white_y, double red_x, double red_y,
  31.    double green_x, double green_y, double blue_x, double blue_y)
  32. {
  33.    png_debug1(1, "in %s storage function\n", "cHRM");
  34.    if (info_ptr == NULL)
  35.       return;
  36.  
  37.    info_ptr->x_white = (float)white_x;
  38.    info_ptr->y_white = (float)white_y;
  39.    info_ptr->x_red   = (float)red_x;
  40.    info_ptr->y_red   = (float)red_y;
  41.    info_ptr->x_green = (float)green_x;
  42.    info_ptr->y_green = (float)green_y;
  43.    info_ptr->x_blue  = (float)blue_x;
  44.    info_ptr->y_blue  = (float)blue_y;
  45.    info_ptr->valid |= PNG_INFO_cHRM;
  46. }
  47. #endif
  48.  
  49. #if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
  50. void
  51. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  52. {
  53.    png_debug1(1, "in %s storage function\n", "gAMA");
  54.    if (info_ptr == NULL)
  55.       return;
  56.  
  57.    info_ptr->gamma = (float)file_gamma;
  58.    info_ptr->valid |= PNG_INFO_gAMA;
  59. }
  60. #endif
  61.  
  62. #if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
  63. void
  64. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  65. {
  66.    png_debug1(1, "in %s storage function\n", "hIST");
  67.    if (info_ptr == NULL)
  68.       return;
  69.  
  70.    info_ptr->hist = hist;
  71.    info_ptr->valid |= PNG_INFO_hIST;
  72. }
  73. #endif
  74.  
  75. void
  76. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  77.    png_uint_32 width, png_uint_32 height, int bit_depth,
  78.    int color_type, int interlace_type, int compression_type,
  79.    int filter_type)
  80. {
  81.    png_debug1(1, "in %s storage function\n", "IHDR");
  82.    if (info_ptr == NULL)
  83.       return;
  84.  
  85.    info_ptr->width = width;
  86.    info_ptr->height = height;
  87.    info_ptr->bit_depth = (png_byte)bit_depth;
  88.    info_ptr->color_type =(png_byte) color_type;
  89.    info_ptr->compression_type = (png_byte)compression_type;
  90.    info_ptr->filter_type = (png_byte)filter_type;
  91.    info_ptr->interlace_type = (png_byte)interlace_type;
  92.    if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  93.       info_ptr->channels = 1;
  94.    else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  95.       info_ptr->channels = 3;
  96.    else
  97.       info_ptr->channels = 1;
  98.    if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  99.       info_ptr->channels++;
  100.    info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  101.    info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
  102. }
  103.  
  104. #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
  105. void
  106. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  107.    png_uint_32 offset_x, png_uint_32 offset_y, int unit_type)
  108. {
  109.    png_debug1(1, "in %s storage function\n", "oFFs");
  110.    if (info_ptr == NULL)
  111.       return;
  112.  
  113.    info_ptr->x_offset = offset_x;
  114.    info_ptr->y_offset = offset_y;
  115.    info_ptr->offset_unit_type = (png_byte)unit_type;
  116.    info_ptr->valid |= PNG_INFO_oFFs;
  117. }
  118. #endif
  119.  
  120. #if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED)
  121. void
  122. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  123.    png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  124.    png_charp units, png_charpp params)
  125. {
  126.    png_size_t length;
  127.    int i;
  128.  
  129.    png_debug1(1, "in %s storage function\n", "pCAL");
  130.    if (info_ptr == NULL)
  131.       return;
  132.  
  133.    length = png_strlen(purpose) + 1;
  134.    png_debug1(3, "allocating purpose for info (%d bytes)\n", length);
  135.    info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length);
  136.    png_memcpy(info_ptr->pcal_purpose, purpose, length);
  137.  
  138.    png_debug(3, "storing X0, X1, type, and nparams in info\n");
  139.    info_ptr->pcal_X0 = X0;
  140.    info_ptr->pcal_X1 = X1;
  141.    info_ptr->pcal_type = (png_byte)type;
  142.    info_ptr->pcal_nparams = (png_byte)nparams;
  143.  
  144.    length = png_strlen(units) + 1;
  145.    png_debug1(3, "allocating units for info (%d bytes)\n", length);
  146.    info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length);
  147.    png_memcpy(info_ptr->pcal_units, units, length);
  148.  
  149.    info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr,
  150.       (nparams + 1) * sizeof(png_charp));
  151.    info_ptr->pcal_params[nparams] = NULL;
  152.  
  153.    for (i = 0; i < nparams; i++)
  154.    {
  155.       length = png_strlen(params[i]) + 1;
  156.       png_debug2(3, "allocating parameter %d for info (%d bytes)\n", i, length);
  157.       info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length);
  158.       png_memcpy(info_ptr->pcal_params[i], params[i], length);
  159.    }
  160.  
  161.    info_ptr->valid |= PNG_INFO_pCAL;
  162. }
  163. #endif
  164.  
  165. #if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
  166. void
  167. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  168.    png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  169. {
  170.    png_debug1(1, "in %s storage function\n", "pHYs");
  171.    if (info_ptr == NULL)
  172.       return;
  173.  
  174.    info_ptr->x_pixels_per_unit = res_x;
  175.    info_ptr->y_pixels_per_unit = res_y;
  176.    info_ptr->phys_unit_type = (png_byte)unit_type;
  177.    info_ptr->valid |= PNG_INFO_pHYs;
  178. }
  179. #endif
  180.  
  181. void
  182. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  183.    png_colorp palette, int num_palette)
  184. {
  185.    png_debug1(1, "in %s storage function\n", "PLTE");
  186.    if (info_ptr == NULL)
  187.       return;
  188.  
  189.    info_ptr->palette = palette;
  190.    info_ptr->num_palette = (png_uint_16)num_palette;
  191.    info_ptr->valid |= PNG_INFO_PLTE;
  192. }
  193.  
  194. #if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
  195. void
  196. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  197.    png_color_8p sig_bit)
  198. {
  199.    png_debug1(1, "in %s storage function\n", "sBIT");
  200.    if (info_ptr == NULL)
  201.       return;
  202.  
  203.    png_memcpy(&(info_ptr->sig_bit), sig_bit, sizeof (png_color_8));
  204.    info_ptr->valid |= PNG_INFO_sBIT;
  205. }
  206. #endif
  207.  
  208. #if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) || \
  209.     defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
  210. void
  211. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  212.    int num_text)
  213. {
  214.    int i;
  215.  
  216.    png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  217.       "text" : png_ptr->chunk_name));
  218.  
  219.    if (info_ptr == NULL || num_text == 0)
  220.       return;
  221.  
  222.    /* Make sure we have enough space in the "text" array in info_struct
  223.     * to hold all of the incoming text_ptr objects.
  224.     */
  225.    if (info_ptr->num_text + num_text > info_ptr->max_text)
  226.    {
  227.       if (info_ptr->text != NULL)
  228.       {
  229.          png_textp old_text;
  230.          int old_max;
  231.  
  232.          old_max = info_ptr->max_text;
  233.          info_ptr->max_text = info_ptr->num_text + num_text + 8;
  234.          old_text = info_ptr->text;
  235.          info_ptr->text = (png_textp)png_malloc(png_ptr,
  236.             info_ptr->max_text * sizeof (png_text));
  237.          png_memcpy(info_ptr->text, old_text, old_max * sizeof(png_text));
  238.          png_free(png_ptr, old_text);
  239.       }
  240.       else
  241.       {
  242.          info_ptr->max_text = num_text + 8;
  243.          info_ptr->num_text = 0;
  244.          info_ptr->text = (png_textp)png_malloc(png_ptr,
  245.             info_ptr->max_text * sizeof (png_text));
  246.       }
  247.       png_debug1(3, "allocated %d entries for info_ptr->text\n",
  248.          info_ptr->max_text);
  249.    }
  250.  
  251.    for (i = 0; i < num_text; i++)
  252.    {
  253.       png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  254.  
  255.       if (text_ptr[i].text == NULL)
  256.          text_ptr[i].text = "";
  257.  
  258.       if (text_ptr[i].text[0] == '\0')
  259.       {
  260.          textp->text_length = 0;
  261.          textp->compression = PNG_TEXT_COMPRESSION_NONE;
  262.       }
  263.       else
  264.       {
  265.          textp->text_length = png_strlen(text_ptr[i].text);
  266.          textp->compression = text_ptr[i].compression;
  267.       }
  268.       textp->text = text_ptr[i].text;
  269.       textp->key = text_ptr[i].key;
  270.       info_ptr->num_text++;
  271.       png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  272.    }
  273. }
  274. #endif
  275.  
  276. #if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
  277. void
  278. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  279. {
  280.    png_debug1(1, "in %s storage function\n", "tIME");
  281.    if (info_ptr == NULL)
  282.       return;
  283.  
  284.    png_memcpy(&(info_ptr->mod_time), mod_time, sizeof (png_time));
  285.    info_ptr->valid |= PNG_INFO_tIME;
  286. }
  287. #endif
  288.  
  289. #if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
  290. void
  291. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  292.    png_bytep trans, int num_trans, png_color_16p trans_values)
  293. {
  294.    png_debug1(1, "in %s storage function\n", "tRNS");
  295.    if (info_ptr == NULL)
  296.       return;
  297.  
  298.    if (trans != NULL)
  299.    {
  300.       info_ptr->trans = trans;
  301.    }
  302.  
  303.    if (trans_values != NULL)
  304.    {
  305.       png_memcpy(&(info_ptr->trans_values), trans_values,
  306.          sizeof(png_color_16));
  307.    }
  308.    info_ptr->num_trans = (png_uint_16)num_trans;
  309.    info_ptr->valid |= PNG_INFO_tRNS;
  310. }
  311. #endif
  312.  
  313.